package com.lyf.emall.controller;

import com.lyf.emall.bean.*;
import com.lyf.emall.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * @Description:
 * @Author Lfy
 * @Date 2022/4/20-14:55
 */
@RestController
public class OrderController {

    @Autowired
    OrderService orderService;

    @GetMapping("/order")
    @PreAuthorize("hasAuthority('/order/list')")
    public ResponseResult getAllOrder(Page page){
        return orderService.getAllOrder(page);
    }

    @GetMapping("/order/deliver")
    @PreAuthorize("hasAuthority('/order/deliver')")
    public ResponseResult deliverGoods(@RequestParam("orderId") String orderId,
                                       @RequestParam("postFee") String postFee,
                                       @RequestParam("shippingName") String shippingName,
                                       @RequestParam("shippingCode") String shippingCode){

        BigDecimal bigDecimal = new BigDecimal(postFee);
        OrderList orderList = new OrderList(orderId, null, null, bigDecimal, null, null, null, null, null, null, null, shippingName, shippingCode, null, null, null, null);

        return orderService.deliverGoods(orderList);
    }

    @PutMapping("/order")
    @PreAuthorize("hasAuthority('/order/remark')")
    public ResponseResult updateOrderRemark(@RequestParam("orderId") String orderId,
                                            @RequestParam("buyerMessage") String buyerMessage){
        return orderService.updateRemark(orderId, buyerMessage);
    }

    @GetMapping("/order/cancel")
    @PreAuthorize("hasAuthority('/order/cancel')")
    public ResponseResult cancelOrder(@RequestParam("orderId") String orderId){
        return orderService.cancelOrder(new OrderList(orderId, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null));
    }

    @GetMapping("/order/info")
    @PreAuthorize("hasAuthority('/order/info')")
    public ResponseResult getOrderInfo(@RequestParam("orderId") String orderId){
        return orderService.getOrderInfo(orderId);
    }
}
